package com.example.teachmvandroidchart.ui

import android.graphics.Color
import android.os.Bundle
import com.android.frame.mvp.CommonBaseActivity
import com.example.teachmvandroidchart.databinding.ActivityCombinedchartBinding
import com.example.teachmvandroidchart.databinding.ActivityMpandroidchartBinding
import com.example.teachmvandroidchart.widget.CombinedChartManager
import com.gyf.immersionbar.ImmersionBar
import java.util.ArrayList

/**
 * Created by dell on 2021/8/11.
 */
class ComBinchartActivity: CommonBaseActivity<ActivityCombinedchartBinding>() {


    override fun handleView(savedInstanceState: Bundle?) {
        intView()
        intDate()
    }
    private fun intView() {
        ImmersionBar.with(this).titleBar(binding.toolbar).keyboardEnable(true).init()
        ImmersionBar.with(this).titleBar(binding.toolbar).init()
        setSupportActionBar(binding.toolbar)
        val actionBar = supportActionBar
        actionBar?.setDisplayHomeAsUpEnabled(true)
    }
    override fun initListener() {

        //toolbar返回按钮监听
        binding.toolbar.setNavigationOnClickListener { finish() }
    }
    private fun intDate(){
        //x轴数据
        val xData: MutableList<String> = ArrayList()
        for (i in 0..20) {
            xData.add(i.toString())
        }
        //y轴数据集合
        val yBarDatas: MutableList<List<Float>> = ArrayList()
        //4种直方图
        for (i in 0..3) {
            //y轴数
            val yData: MutableList<Float> = ArrayList()
            for (j in 0..20) {
                yData.add((Math.random() * 100).toFloat())
            }
            yBarDatas.add(yData)
        }
        //y轴数据集合
        val yLineDatas: MutableList<List<Float>> = ArrayList()
        //4种直方图
        for (i in 0..3) {
            //y轴数
            val yData: MutableList<Float> = ArrayList()
            for (j in 0..20) {
                yData.add((Math.random() * 100).toFloat())
            }
            yLineDatas.add(yData)
        }
        //名字集合
        val barNames: MutableList<String> = ArrayList()
        barNames.add("直方图一")
        barNames.add("直方图二")
        barNames.add("直方图三")
        barNames.add("直方图四")
        //颜色集合
        val colors: MutableList<Int> = ArrayList()
        colors.add(Color.BLUE)
        colors.add(Color.RED)
        colors.add(Color.YELLOW)
        colors.add(Color.CYAN)
        //竖状图管理类
        val lineNames: MutableList<String> = ArrayList()
        lineNames.add("折线图一")
        lineNames.add("折线图二")
        lineNames.add("折线图三")
        lineNames.add("折线图四")


        //管理类
        val combineChartManager1 = CombinedChartManager(binding.chart1)
        combineChartManager1.showCombinedChart(xData, yBarDatas.get(0), yLineDatas.get(0),
                "直方图", "线性图", colors.get(0), colors.get(1));

        val combineChartManager2 = CombinedChartManager(binding.chart2)
        combineChartManager2.showCombinedChart(
            xData, yBarDatas, yLineDatas, barNames, lineNames,
            colors, colors
        )

    }




}